﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Renci.iRods.Common;

namespace Renci.iRods.Data
{
    public abstract class FileSystemDataItem : MetaDataItem
    {
        public abstract string Name { get; internal set; }

        public abstract string FullName { get; internal set; }

        /// <summary>
        /// Gets or sets the creation time of the current System.IO.FileSystemInfo object.
        /// </summary>
        /// <value>
        /// The creation time.
        /// </value>
        public abstract DateTime CreationTime { get; internal set; }

        public abstract DateTime LastWriteTime { get; internal set; }

        internal FileSystemDataItem(IRodsConnection connection, string fullName, string metadataType)
            : base(connection, metadataType)
        {
            if (!string.IsNullOrEmpty(fullName))
                this.FullName = this.Connection.ParsePath(fullName);
        }

        /// <summary>
        /// Deletes a file or collection.
        /// </summary>
        public abstract void Delete();

        protected string GetFullPath(string path)
        {
            var index = path.LastIndexOf('/');
            if (index > 0)
            {
                return path.Substring(0, index);
            }
            else
            {
                return string.Empty;
            }
        }
    }
}
